package com.example.mall.controller.cms;

import com.example.mall.common.core.response.SuccessResponse;
import com.example.mall.common.utils.SuccessHelper;
import com.example.mall.entity.Order;
import com.example.mall.service.OrderService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Autowired
    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @GetMapping("/list")
    public SuccessResponse getAll() {
        List<Order> orderList = orderService.selectAll();
        return SuccessHelper.excute("orderList", orderList);
    }

    @GetMapping("/save")
    public String save(Order order) {
        int id = orderService.save(order);
        System.out.println("保存成功: " + id);
        return "保存成功";
    }
}
